package com.jumi.microservice.stock.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.jumi.microservice.common.constant.IsDeletedEnum;
import com.jumi.microservice.common.utils.BeanCopierUtils;
import com.jumi.microservice.stock.domain.StockCheckLogDO;
import com.jumi.microservice.stock.domain.StockCheckLogVO;
import com.jumi.microservice.stock.mapper.StockCheckLogMapper;
import com.jumi.microservice.stock.service.StockCheckLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @ClassName StockCheckLogServiceImpl
 * @Author Abel Yang
 * @Date 2020/9/18/018 17:08
 **/
@Service
public class StockCheckLogServiceImpl implements StockCheckLogService {

    @Resource
    private StockCheckLogMapper stockCheckLogMapper;

    @Override
    public List<StockCheckLogVO> getList(Byte checkType, Long applyId) {
        List<StockCheckLogVO> result = Lists.newArrayList();
        List<StockCheckLogDO> logList = stockCheckLogMapper.selectList(
                Wrappers.<StockCheckLogDO>lambdaQuery()
                        .eq(StockCheckLogDO::getCheckType, checkType)
                        .eq(StockCheckLogDO::getApplyId, applyId)
                        .eq(StockCheckLogDO::getIsDel, IsDeletedEnum.NO)
        );
        if (logList.size() == 0) {
            return result;
        }
        logList.forEach(logDO -> {
            StockCheckLogVO logVO = new StockCheckLogVO();
            BeanCopierUtils.copyProperties(logDO, logVO);
            logVO.setCheckTimeStr(logDO.getCreateTime());
            result.add(logVO);
        });
        return result;
    }
}
